﻿using KingsSharp.Common;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using CRM.Admin.Contracts.Contract.Sys;
using CRM.Admin.Contracts.Model.Sys;
using System;
using System.Linq;

namespace Property.Main.Services.Service.Sys
{
    public class AuthorizationService:ServiceBase,IAuthorizationService
    {
        private IRepository<Authorization, Guid> AuthorizationRepository;
        public AuthorizationService(IRepository<Authorization, Guid> _AuthorizationRepository)
            :base(_AuthorizationRepository.UnitOfWork)
        {
            AuthorizationRepository = _AuthorizationRepository;
        }

        public IQueryable<Authorization> ItemAuthorization
        {
            get { return AuthorizationRepository.Entities; }
        }

        public KingsSharp.Common.Data.OperationResult InsertAuthorization(params CRM.Admin.Contracts.Dto.Sys.AuthorizationDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            return AuthorizationRepository.Insert(dtos);
        }

        public KingsSharp.Common.Data.OperationResult UpdateAuthorization(params CRM.Admin.Contracts.Dto.Sys.AuthorizationDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            return AuthorizationRepository.Update(dtos);
        }
        public KingsSharp.Common.Data.OperationResult InsertOrUpdateAuthorization(Guid RoleId,params CRM.Admin.Contracts.Dto.Sys.AuthorizationDto[] dtos)
        {
            RoleId.CheckNotEmpty("RoleId");
            dtos.CheckNotNull("dtos");
            AuthorizationRepository.Delete(a => a.RoleId == RoleId);
            return AuthorizationRepository.Insert(dtos);
        }
        public KingsSharp.Common.Data.OperationResult DeleteAuthorization(params Guid[] ids)
        {
            ids.CheckNotNull("dtos");
           return AuthorizationRepository.Delete(ids);
        }
    }
}
